
<template>
  <div class="dx-detail-container">
    <div style="height: 50px; width: 100%; margin-top: 15px">
      <el-input placeholder="根据名称检索" v-model="input3" class="input-with-select">
        <el-button slot="append" icon="el-icon-search" @click="inputChange"></el-button>
      </el-input>
    </div>
    <div class="dx-body-container">
      <div v-for="(item, index) in tableList" :key="item.id" class="list-container" :class="activeEventid === item.eventid ? 'active-project' : ''">
        <div class="list-index">{{ index + 1 }}</div>
        <div class="list-checkbox" v-if="menuType !== 'text'">
          <el-checkbox v-model="item.isChecked" @change.native="drawEntity(item, 'check')"></el-checkbox>
        </div>
        <div class="list-body">
          <div class="list-line">
            <div class="list-line-name" @click="drawEntity(item)">
              {{ item.name || item.num }}
            </div>
            <div v-if="
                menuType === 'drilling' ||
                menuType === 'profile' ||
                menuType === 'plane' ||
                menuType === 'model'
              " class="list-line-icon">
              <i v-if="menuType === 'drilling'" class="el-icon-view" @click.stop="showdrilling(item)"></i>
              <i v-if="menuType === 'plane'" class="el-icon-view" @click.stop="showplane(item)"></i>
              <i v-if="menuType === 'model' && item.geological" class="el-icon-film" @click.stop="showModelProfileLine(item)"></i>
              <i v-if="menuType === 'model' && item.geological" class="el-icon-s-help" @click.stop="showModelDrillHole(item)"></i>
              <i v-if="menuType === 'model'" class="dx-moxing2" @click.stop="showThreeModel(item)"></i>
              <i v-if="menuType === 'profile'" class="el-icon-view" @click.stop="showProfileDetail(item)"></i>
              <i class="el-icon-s-promotion" @click.stop="flyTOTheEntity(item)"></i>
            </div>
          </div>
          <!-- <div class="list-line" v-if="menuType !== 'text' && menuType !== 'model'" >
            <div class="list-line-lable">{{ item.projectnumber }}</div>
            <div class="list-line-lable" style="text-align: right"></div>
          </div> -->
          <div class="list-line" v-if="menuType === 'text'">
            <div class="list-line-lable">类型：{{ item.type }}</div>
            <div class="list-line-lable" style="text-align: right">
              <i class="el-icon-view" v-if="item.type !== 'doc'" @click.stop="showPdf(item)" style="margin-right: 10px"></i>
              <i v-if="region !== 'guest'" class="el-icon-download" @click.stop="fileDown(item)"></i>
            </div>
          </div>
        </div>
      </div>
    </div>
    <div v-if="
        menuType === 'drilling' ||
        menuType === 'plane' ||
        menuType === 'profile'
      " class="dx-footer-container" style="
        display: flex;
        padding-left: 35px;
        justify-content: flex-start;
        align-items: center;
      ">
      <el-checkbox v-model="checkAll" @change="checkAllChange">全选</el-checkbox>
    </div>
    <div v-if="loading" class="loaing-box">
      <i class="el-icon-loading"></i>
      <span>数据正在绘制中，请耐心等待</span>
    </div>
  </div>
</template>

<script>
import axios from "axios";

import DataOptions from "./dataOptions";
import Pagination from "@/components/Pagination/index.vue";
import DxCommonUtils from "@/utils/cesiumDxUtils/common3D";
import { getToken, getRole } from "@/utils/auth"; // get token from cookie
import pdf from "vue-pdf";

import * as turf from "@turf/turf";

var destoryTilese = null;
var tileseList = [];
// import { mapState } from "vuex";
// import cesiumInit from "./index";
export default {
  name: "DataDisplay",
  inject: ["upDataDetailId"],

  data() {
    return {
      TZId: [],
      pliAct: true,
      proData: "",
      menuType: null, // 菜单类型
      tableList: [],
      parameters: {
        page: 1,
        total: 60,
        limit: 20,
      },
      loading: false,
      input3: "",
      checkAll: false,
      dataAllLit: [],
      activeEventid: null,
      pageNum: 1,
      pageTotalNum: 1, // # 总页数
      loadedRatio: 0, //  # 当前页面的加载进度，范围是0-1 ，等于1的时候代表当前页已经完全加载完成了

      numPages: null, // pdf 总页数
      pdfurl: null, // "@/assets/dataImg/01韩家湾瞬变电磁探测成果报告.pdf",
      activeId: null,
      region: getRole(),
      TZImg: {
        T1Z: require('./img/T1Z.png'),
        T2Z: require('./img/T2Z.png'),
        T3Z: require('./img/T3Z.png'),
        T4Z: require('./img/T4Z.png'),
        T5Z: require('./img/T5Z.png'),
        T6Z: require('./img/T6Z.png'),
      }
    };
  },
  components: {
    Pagination,
    pdf,
  },
  created() {
    this.initDiaplayPage();
    this.region = getRole();
  },
  mounted() {
    const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
    handler.setInputAction((clickEvent) => {
      var pick = viewer.scene.pick(clickEvent.position);
      if (Cesium.defined(pick) && pick.id && pick.id._name) {
        let id = null;
        if (pick.id._name === "zhuankong") {
          id = pick.id._id.replace("zhuankong", "");
          if (this.activeEventid && this.activeEventid !== id) {
            this.proData.handleDrawEntities.backOriginalStyle(
              this.activeEventid
            );
          }
          this.activeEventid = id;
          this.proData.handleDrawEntities.changeProfileStyle(
            this.activeEventid
          );
        } else if (pick.id._name.includes("poumian")) {
          id = pick.id._id.replace("poumian", "");
          if (this.activeEventid && this.activeEventid !== id) {
            this.proData.handleDrawEntities.backOriginalStyle(
              this.activeEventid
            );
          }
          this.activeEventid = id;
          this.proData.handleDrawEntities.changeProfileStyle(
            this.activeEventid
          );
        } else if (pick.id._name === "poumianDian") {
          const index = pick.id._id.lastIndexOf("poumianDian");
          const str = pick.id._id;
          id = str.substring(index + 11, str.length);
          if (this.activeEventid && this.activeEventid !== id) {
            this.proData.handleDrawEntities.backOriginalStyle(
              this.activeEventid
            );
          }
          this.activeEventid = id;
          this.proData.handleDrawEntities.changeProfileStyle(
            this.activeEventid
          );
        } else if (pick.id._name === "plane") {
          id = pick.id._id.replace("plane", "");
          if (this.activeEventid && this.activeEventid !== id) {
            this.proData.handleDrawEntities.backOriginalStyle(
              this.activeEventid
            );
          }
          this.activeEventid = id;
          this.proData.handleDrawEntities.changeProfileStyle(
            this.activeEventid
          );
        }
        this.upDataDetailId(id);
      }
    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);

    DxCommonUtils.handleAdd3DTileset.initManager();
  },
  methods: {
    showplane(data) {
      if (this.activeEventid && this.activeEventid !== data.eventid) {
        this.proData.handleDrawEntities.backOriginalStyle(this.activeEventid);
      }
      this.activeEventid = data.eventid;
      this.proData.handleDrawEntities.changeProfileStyle(this.activeEventid);
      this.upDataDetailId(data.eventid);
    },
    showdrilling(data) {
      if (this.activeEventid && this.activeEventid !== data.eventid) {
        this.proData.handleDrawEntities.backOriginalStyle(this.activeEventid);
      }
      this.activeEventid = data.eventid;
      this.proData.handleDrawEntities.changeProfileStyle(this.activeEventid);
      this.upDataDetailId(data.eventid);
      // this.proData.handleDrawEntities.backOriginalStyle(data.eventid);
    },
    showProfileDetail(data) {
      this.upDataDetailId(data.eventid);
      const id = data.eventid;
      if (this.activeEventid && this.activeEventid !== id) {
        this.proData.handleDrawEntities.backOriginalStyle(this.activeEventid);
      }
      this.activeEventid = id;
      this.proData.handleDrawEntities.changeProfileStyle(this.activeEventid);
    },
    // 初始化页面
    initDiaplayPage() {
      DxCommonUtils.removeAllEntities();
      const query = this.$route.query.type || null;
      if (!query) return;
      this.proData = DataOptions.fieldlabel[query];
      this.menuType = this.proData.usName;
      // 设置页数
      this.parameters.total = this.proData["total"] || 0;
      // 初始化数据
      this.tableList = DataOptions[query].slice(0, this.parameters.limit);

      // 获取后台数据
      this.getData();
    },
    // 文件下载
    fileDown(data) {
      window.location = data.url;
    },
    // showPdf(data) {
    //   data
    //   this.showPdf(data.url);
    // },
    // 获取后台数据
    getData() {
      this.checkAll = false;
      if (this.proData.usName === "drilling") {
        const obj = {
          page: this.parameters.page,
          size: this.parameters.limit,
          projectnumber: this.$store.getters.proNum,
        };
        this.proData.listData(obj).then((resp) => {
          if (resp.list.length === 0) {
            this.loading = false;
          } else {
            this.loading = true;
            this.parameters.total = resp.total || 0;
            this.dataAllLit =
              resp.list.map((item) => {
                item.isChecked = true;
                return item;
              }) || [];
            this.tableList = [].concat(
              this.dataAllLit // .slice(0, this.parameters.limit)
            );
            DataOptions[this.proData.usName] = this.tableList;
            // 设置全选，并绘制点全部数据
            this.checkAll = true;
            this.checkAllChange();
            this.proData.handleDrawEntities.init(this.tableList);
            setTimeout(() => {
              this.loading = false;
            }, 1000);
          }
        });
      } else if (
        this.proData.usName === "profile" ||
        this.proData.usName === "plane"
      ) {
        this.loading = true;
        const obj = {
          page: this.parameters.page,
          size: this.parameters.limit,
          projectnumber: this.$store.getters.proNum,
        };
        this.proData.listData(obj).then((resp) => {
          if (resp.detail.length === 0) {
            this.$message({
              type: "info",
              message: "暂无数据",
            });
            this.loading = false;
          } else {
            setTimeout(() => {
              this.loading = false;
              this.parameters.total = resp.detail.length || 0;
              this.dataAllLit =
                resp.detail.map((item) => {
                  item.isChecked = true;
                  return item;
                }) || [];
              this.tableList = [].concat(
                this.dataAllLit // .slice(0, this.parameters.limit)
              );
              DataOptions[this.proData.usName] = this.tableList;
              // 设置全选，并绘制点全部数据
              this.checkAll = true;
              this.checkAllChange();
              this.proData.handleDrawEntities.init(this.tableList);
            }, 1000);
          }
        });
      } else if (this.proData.usName === "model") {
        const obj = {
          page: this.parameters.page,
          size: this.parameters.limit,
          projectnumber: this.$store.getters.proNum,
        };
        this.proData.listData(obj).then((resp) => {
          if (resp.length === 0) {
            this.$message({
              type: "info",
              message: "暂无数据",
            });
            return;
          }
          this.dataAllLit = resp.length
            ? resp.map((item) => {
              item.isChecked = false;
              item.geological = item.modelType !== "building";
              item.name =
                item.fileModel && item.fileModel.length
                  ? item.fileModel[0].name
                  : "模型";
              return item;
            })
            : [];
          this.tableList = [].concat(
            this.dataAllLit // .slice(0, this.parameters.limit)
          );
          DataOptions[this.proData.usName] = this.tableList;
          // 绘制模型边界
          DxCommonUtils.handleAdd3DTileset.drawOutLIne(this.tableList[0]);
          // // 设置全选，并绘制点全部数据
          // this.checkAll = true;
          // this.checkAllChange();
          console.log("this.dataAllLit =", this.dataAllLit);
        });
      } else if (this.proData.usName === "text") {
        const obj = {
          page: this.parameters.page,
          size: this.parameters.limit,
          projectnumber: this.$store.getters.proNum,
        };
        this.proData.listData(obj).then((resp) => {
          this.parameters.total = resp.files.length || 0;
          this.dataAllLit = resp.files.concat(resp.pdf);
          if (this.dataAllLit.length === 0) {
            this.$message({
              type: "info",
              message: "暂无数据",
            });
          } else {
            this.tableList = [].concat(
              this.dataAllLit // .slice(0, this.parameters.limit)
            );
          }

          // resp.detail.map((item) => {
          //   item.isChecked = true;
          //   return item;
          // }) || [];

          // 设置全选，并绘制点全部数据
          // this.checkAll = true;
          // this.checkAllChange();
        });
      } else {
        this.tableList = DataOptions[this.proData.usName].slice(
          0,
          this.parameters.limit
        );
        DataOptions[this.proData.usName] = this.tableList;
      }
      // getAllDrillings
    },
    closeContainer() {
      this.$router.go(-1);
    },
    handleClick(row) { },
    delTheData() {
      this.$confirm("此操作将永久删除该文件, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.$message({
            type: "success",
            message: "删除成功!",
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除",
          });
        });
    },
    // 处理数据
    settableList() {
      this.getData();
      // const s = (this.parameters.page - 1) * this.parameters.limit + 0;
      // const e =
      //   (this.parameters.page - 1) * this.parameters.limit +
      //   this.parameters.limit;
      // this.tableList = DataOptions[this.proData.usName].slice(s, e);
    },
    // 输入框
    inputChange() {
      if (this.input3) {
        this.tableList = DataOptions[this.proData.usName].filter((item) => {
          if (
            (item.name && item.name.includes(this.input3)) ||
            (item.num && item.num.includes(this.input3))
          ) {
            return item;
          }
        });
      } else {
        this.settableList();
      }
    },
    // 切换分页
    changePagination(data) {
      this.parameters.page = data.page;
      this.settableList();
    },
    // 全选
    checkAllChange() {
      this.checkAll
        ? this.tableList.forEach((item) => (item.isChecked = true))
        : this.tableList.forEach((item) => (item.isChecked = false));
      if (this.proData.usName === "model") {
        tileseList.forEach((item) => {
          item.tilese3d.show = this.checkAll;
        });
      }
      this.proData.handleDrawEntities &&
        this.proData.handleDrawEntities.SourceshowHide(this.checkAll);
      // 绘制实体
      // this.drawMoreEntity();
    },
    // 选中单个
    checkBoxChange(data) {
      const checkedLis = this.tableList.filter((item) => item.isChecked);
      if (checkedLis.length === this.tableList.length) {
        this.checkAll = true;
      } else {
        this.checkAll = false;
      }
      // // 绘制实体
      // this.drawMoreEntity();
    },
    // 绘制实体
    drawEntity(data, type = null) {
      if (!type) {
        data.isChecked = !data.isChecked;
      }
      if (
        this.activeEventid &&
        this.activeEventid !== data.eventid &&
        this.menuType !== "model"
      ) {
        this.activeEventid &&
          this.proData.handleDrawEntities.backOriginalStyle(this.activeEventid);
      }

      this.activeEventid = data.isChecked ? data.eventid : null;
      if (this.menuType === "model") {
        this.activeEventid = data.eventid;

        this.$store.commit("app/UPDATA_SHOWTHREE", true);
        this.$store.commit("app/UPDATA_threeFullScreen", false);

        // 判断是否重新绘制
        const activemode =
          tileseList.find((item) => item.eventid === data.eventid) || null;
        if (activemode) {
          activemode.tilese3d.show = !activemode.tilese3d.show;
          return;
        }

        if (data.centerCoor && data.centerCoor.length) {
          destoryTilese = DxCommonUtils.handleAdd3DTileset.init({
            tileUrl: data.tileUrl,
            center: data.centerCoor,
          });
          const oobbjj = Object.assign(data, { tilese3d: destoryTilese });
          tileseList.push(oobbjj);
          oobbjj.tilese3d.show = data.isChecked;

          // 根据经纬度，获取高度

          // destoryTilese && (destoryTilese.show = false);
          // if (data.centerCoor && data.centerCoor.length) {
          //   debugger;
          //   if (!DxCommonUtils.dxTiles) {
          //     DxCommonUtils.dxTiles = new DxCommonUtils.DxTiles({
          //       viewer: viewer,
          //     });
          //   }

          //   debugger

          // DxCommonUtils.dxTiles.addSingletiles({
          //   tileModel: null,
          //   id: "Photography-01",
          //   tileUrl: data.tileUrl,
          //   name: 'XXX',
          //   maxtrixObj: {
          //     sc: 1.0,
          //     lon: data.centerCoor[0],
          //     lat: data.centerCoor[1],
          //     ht: data.centerCoor[2],
          //     tileModel: null,
          //     rx: 0, ry: 0, rz: 0, ap: 1.0, tileModel: null

          //   },
          // });
          // destoryTilese = DxCommonUtils.handleAdd3DTileset.init({
          //   tileUrl: data.tileUrl,
          //   center: data.centerCoor,
          // });
          // const oobbjj = Object.assign(data, { tilese3d: destoryTilese });
          // tileseList.push(oobbjj);
          // oobbjj.tilese3d.show = data.isChecked;
        }
      } else {
        // 根据类型判断，
        if (this.proData.usName === "drilling") {
          DxCommonUtils.toolsList.entityShowHiddenInversion({
            sourceID: "turnEntities",
            entityID: "zhuankong" + data.eventid,
          });
          if (this.activeEventid) {
            this.proData.handleDrawEntities.changeProfileStyle(data.eventid);
          }
        } else if (this.proData.usName === "profile") {
          DxCommonUtils.toolsList.entityShowHiddenInversion({
            sourceID: "profileEntities",
            // activeSource: true,
            entityID: "poumian" + data.eventid,
          });
          DxCommonUtils.toolsList.entityShowHiddenInversion({
            sourceID: "poumianDian" + data.eventid,
            activeSource: true,
          });
          // data.isChecked &&
          //   this.proData.handleDrawEntities.changeProfileStyle(
          //     data.eventid
          //   );
        } else if (this.proData.usName === "plane") {
          DxCommonUtils.toolsList.entityShowHiddenInversion({
            sourceID: "planeEntities" + data.eventid,
            activeSource: true,
          });

          data.isChecked &&
            this.proData.handleDrawEntities.changeProfileStyle(
              this.activeEventid
            );
          // DxCommonUtils.toolsList.entityShowHiddenInversion({
          //   sourceID: "planeEntities",
          //   entityID: "planeOutLIne" + data.eventid,
          // });
        }
        // this.drawMoreEntity();
        // this.flyToThis(data);
      }
      this.checkBoxChange(data);
    },
    // 打开three模型
    showThreeModel(data) {
      if (!data.isChecked) {
        this.$message({
          message: "实体没有被绘制",
          type: "warning",
        });
        return;
      }
      if (!data.fileModel) {
        this.$message({
          message: "暂时没有获得模型的链接",
          type: "warning",
        });
        return;
      }
      if (data.fileModel && data.fileModel.length) {
        const fbxOBj = data.fileModel[0];
        if (fbxOBj.type === "fbx" || fbxOBj.type === "FBX") {
          // 打开threejs
          this.activeEventid = data.eventid;
          this.$store.commit("app/UPDATA_SHOWTHREE", true);
          this.$store.commit("app/UPDATA_threeFullScreen", false);
          setTimeout(() => {
            this.$store.commit("app/UPDATA_SHOWTHREE", {
              isShowThree: true,
              fbx: fbxOBj.url,
              obj: null,
              mtl: null,
            });
          }, 300);
        }
      }
    },
    showModelDrillHole(data) {
      if (!data.isChecked) {
        this.$message({
          message: "实体没有被绘制",
          type: "warning",
        });
        return;
      }
      if (!data.fileModel) {
        this.$message({
          message: "暂时没有获得模型的链接",
          type: "warning",
        });
        return;
      }
      // if (!this.pliAct) {
      //   cesiumInit.destroy();
      //   this.pliAct = true;
      //   return;
      // }
      this.$message({
        message: "请在模型上选择钻孔点，按鼠标右键结束",
        type: "primary",
      });

      if (data.jsonurl && data.imgurl) {
        fetch(data.jsonurl)
          .then(function (response) {
            return response.json();
          })
          .then((resp) => {

            const target = resp;
            let section = 0;
            if (target.features.length >= 10000) {
              section = 60
            } else if (target.features.length < 10000 && target.features.length >= 5000) {
              section = 50
            } else if (target.features.length < 5000 && target.features.length >= 1000) {
              section = 20
            } else if (target.features.length < 1000 && target.features.length >= 500) {
              section = 10
            } else if (target.features.length < 500) {
              section = 4
            }
            
            var handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
            handler.setInputAction((event) => {
              const TZ = ['T10Z', 'T9Z', 'T8Z', 'T7Z', 'T6Z', 'T5Z', 'T4Z', 'T3Z', 'T2Z', 'T1Z'];
              // for (let i = 0; i < TZ.length; i++) {
              //   const ent = viewer.entities.getById(TZ[i]);
              //   ent && viewer.entities.remove(ent)
              // }
              // if (TZId.length) {
              //   const n = TZId.length;
              //   for (let j = n - 1; j >= 0; j--) {
              //     const ent = viewer.entities.getById(TZId[j]);
              //     ent && viewer.entities.remove(ent);
              //     TZId.splice(j, 1)
              //   }
              // }
              var earthPosition = viewer.camera.pickEllipsoid(event.position, viewer.scene.globe.ellipsoid);
              var cartographic = Cesium.Cartographic.fromCartesian(earthPosition, viewer.scene.globe.ellipsoid, new Cesium.Cartographic());
              var lat = Cesium.Math.toDegrees(cartographic.latitude);
              var lng = Cesium.Math.toDegrees(cartographic.longitude);

              const coordinate = []
              for (let i = 0; i < data.coordinates.length; i += 2) {
                coordinate.push([data.coordinates[i], data.coordinates[i + 1]]);
              }
              const point = turf.point([lng, lat]);
              const polygon = turf.polygon([coordinate]);
              const inpo = turf.booleanPointInPolygon(point, polygon);
              if (!inpo) {
                this.$message({
                  message: "点不在模型上,或者请移动一下位置从新选取钻孔点",
                  type: "warning",
                });
                return;
              }
              const coordinates = [];
              const targetList = {};
              for (let i = 0; i < target.features.length; i++) {
                const feature = target.features[i]
                if (i % section !== 0) { continue }
                const id = this._randomString()
                if (feature.geometry.coordinates[2]) {
                  feature.geometry.coordinates.pop()
                }
                feature.geometry.coordinates.push(id)
                coordinates.push(turf.point(feature.geometry.coordinates))
                targetList[id] = feature.properties
              }
              var coordPoints = turf.featureCollection(coordinates);
              var nearest = turf.nearestPoint(point, coordPoints);
              const nearId = nearest.geometry.coordinates[2]
              const properties = targetList[nearId];
              if (!properties) {
                this.$message({
                  message: "请从新点击",
                  type: "warning",
                });
                return
              }
              const TzTarget = {};
              let height = 0;
              for (let i = 0; i < TZ.length; i++) {
                if (properties[TZ[i]] && properties[TZ[i + 1]]) {

                  TzTarget[TZ[i]] = {
                    center: [lng, lat, height], // center.push(height),
                    length: parseInt(properties[TZ[i + 1]] - properties[TZ[i]]),
                    material: new Cesium.ImageMaterialProperty({
                      image: this.TZImg[TZ[i + 1]],
                      repeat: new Cesium.Cartesian2(16.0, 16.0)
                    })
                  }
                  height += parseInt(properties[TZ[i + 1]] - properties[TZ[i]]);
                }
              }
              Object.keys(TzTarget).forEach(key => {
                const idd = this._randomString(16);
                this.TZId.push(idd)
                viewer.entities.add({
                  id: idd,
                  position: Cesium.Cartesian3.fromDegrees(TzTarget[key].center[0], TzTarget[key].center[1], TzTarget[key].center[2]),
                  cylinder: {
                    length: TzTarget[key].length,
                    topRadius: 6,
                    bottomRadius: 6,
                    heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND, // CLAMP_TO_GROUND, // RELATIVE_TO_GROUND 
                    material: TzTarget[key].material, // Cesium.Color.BLUE
                  }
                });
              })
            }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
            handler.setInputAction(() => {
              handler.destroy();
              if (this.TZId.length) {
                const n = this.TZId.length;
                for (let j = n - 1; j >= 0; j--) {
                  const ent = viewer.entities.getById(this.TZId[j]);
                  ent && viewer.entities.remove(ent);
                  this.TZId.splice(j, 1)
                }
              }
            }, Cesium.ScreenSpaceEventType.RIGHT_CLICK);
          });
      } else {
        this.$message({
          message: "暂无数据",
          type: "warning",
        });
      }
    },
    _randomString(length) {
      let len = length || 16;
      let $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefhijklmnopqrstuvwxyz123456789'
      let maxLen = $chars.length
      let str = ''
      for (let i = 0; i < len; i++) {
        str += $chars.charAt(Math.floor(Math.random() * maxLen))
      }
      return str
    },
    // 地质剖切
    showModelProfileLine(data) {
      if (!data.isChecked) {
        this.$message({
          message: "实体没有被绘制",
          type: "warning",
        });
        return;
      }
      if (!data.fileModel) {
        this.$message({
          message: "暂时没有获得模型的链接",
          type: "warning",
        });
        return;
      }
      if (!this.pliAct) {
        cesiumInit.destroy();
        this.pliAct = true;
        return;
      }

      if (data.jsonurl && data.imgurl) {
        fetch(data.jsonurl)
          .then(function (response) {
            return response.json();
          })
          .then((resp) => {
            debugger
            cesiumInit.init(viewer, resp, data.imgurl);
            this.pliAct = false;
          });
      } else {
        this.$message({
          message: "暂无数据",
          type: "warning",
        });
      }
    },
    // 飞入实体
    flyTOTheEntity(data) {
      // 判断是否绘制
      if (
        this.proData.usName === "drilling" ||
        this.proData.usName === "profile" ||
        this.proData.usName === "plane"
      ) {
        if (!data.isChecked) {
          this.$message({
            message: "实体没有被绘制",
            type: "warning",
          });
          return;
        }
      } else if (this.proData.usName === "model" && !data.isChecked) {
        this.$message({
          message: "实体没有被绘制",
          type: "warning",
        });
        return;
      }
      //  此时说明实体已经绘制
      // 根据id找实体
      if (this.proData.usName === "drilling") {
        if (this.activeEventid) {
          this.proData.handleDrawEntities.backOriginalStyle(this.activeEventid);
        }
        this.activeEventid = data.eventid;
        const entBox = this.proData.handleDrawEntities.changeProfileStyle(
          this.activeEventid
        );
        viewer.flyTo(entBox);
      } else if (this.proData.usName === "profile") {
        if (this.activeEventid) {
          this.proData.handleDrawEntities.backOriginalStyle(this.activeEventid);
        }
        this.activeEventid = data.eventid;
        const entBox = this.proData.handleDrawEntities.changeProfileStyle(
          this.activeEventid
        );
      } else if (this.proData.usName === "plane") {
        if (this.activeEventid) {
          this.proData.handleDrawEntities.backOriginalStyle(this.activeEventid);
        }
        this.activeEventid = data.eventid;
        const entBox = this.proData.handleDrawEntities.changeProfileStyle(
          this.activeEventid
        );
        viewer.flyTo(entBox);
      } else if (this.proData.usName === "model") {
        this.activeEventid = data.eventid;
        if (destoryTilese) {
          viewer.zoomTo(
            destoryTilese,
            new Cesium.HeadingPitchRange(
              -0.5,
              -5.0,
              destoryTilese.boundingSphere.radius * 1.0
            )
          );
        } else {
          this.$message({
            message: "实体没有被绘制",
            type: "warning",
          });
        }
      }
      // DxCommonUtils.cameraFlyTo({
      //   x: data.coordinates[0],
      //   y: data.coordinates[1],
      //   z: zgao,
      //   heading: 0,
      //   pitch: -90,
      //   roll: 0,
      // });
    },
    // 批量绘制
    drawMoreEntity() {
      // if (this.proData.usName === "model") {
      //   return;
      // }
      // const checkedLis = this.tableList.filter((item) => item.isChecked);
      // if (checkedLis.length === 0) {
      //   // 提示没有选中任何一个
      // }
    },
    // 飞入
    flyToThis(dat) {
      DxCommonUtils.cameraFlyTo({
        x: dat.coordinates[0],
        y: dat.coordinates[1] - 0.03,
        z: 8000,
      });
    },
    // 打开pdf
    showPdf(data) {
      if (data.type === "doc") {
        // const url = "http://view.officeapps.live.com/op/view.aspx?src=" + data.url;
        const url =
          "https://view.xdocin.com/view?func=deadline&src=" + data.url;
        window.open(url);
      } else {
        // 引入原生的axios,不作封装处理
        this.loading = true;
        axios({
          method: "GET",
          url: data.url,
          responseType: "blob", // 更改responseType类型为 blob
        })
          .then((res) => {
            this.loading = false;
            // data = res;
            const blob = new Blob([res.data], { type: "application/pdf" });
            const url = window.URL.createObjectURL(blob);
            window.open(url);
          })
          .catch(() => {
            this.loading = false;
          });

        // 转换pdf

        // this.getNumPages(data);
      }
    },
    getNumPages(data) {
      fetch(data.url, {
        method: "get",
        responseType: "blob",
        ContentType: "application/json;charset=UTF-8",
      })
        .then((res) => {
          return res.blob();
        })
        .then((blob) => {
          var filename = `pdf文件.pdf`;
          var a = document.createElement("a");
          // this.pdfurl
          const url = window.URL.createObjectURL(blob);
          // url = encodeURI(url);
          window.open(url);
          // a.href = url;
          // a.download = filename;
          // window.open(url);
          // a.click();
          // window.URL.revokeObjectURL(url);
        });
    },
    // 上一页
    prePage() {
      let page = this.pageNum;
      page = page > 1 ? page - 1 : this.pageTotalNum;
      this.pageNum = page;
    },
    // 下一页
    nextPage() {
      let page = this.pageNum;
      page = page < this.pageTotalNum ? page + 1 : 1;
      this.pageNum = page;
    },
    closePdf() {
      this.pdfurl = null;
    },
  },
  watch: {
    $route: {
      handler(val, oldval) {
        this.input3 = null;
        this.proData &&
          this.proData.handleDrawEntities.SourceshowHide &&
          this.proData.handleDrawEntities.SourceshowHide(false);
        setTimeout(() => {
          tileseList.forEach((item) => {
            item.tilese3d.show = false;
          });
          var box = viewer.entities.getById("modelOutLIne");
          viewer.entities.remove(box);
          DxCommonUtils.handleAdd3DTileset.deletes();

          cesiumInit.destroy();
          if (val.query.type !== oldval.query.type) {
            this.upDataDetailId(null);
            this.initDiaplayPage();
          }
          if (this.TZId.length) {
            const n = this.TZId.length;
            for (let j = n - 1; j >= 0; j--) {
              const ent = viewer.entities.getById(this.TZId[j]);
              ent && viewer.entities.remove(ent);
              this.TZId.splice(j, 1)
            }
          }
        }, 600);
      },
      // 深度观察监听
      deep: true,
    },
  },
  beforeDestroy() {
    this.$store.commit("app/UPDATA_SHOWTHREE", true);
    this.$store.commit("app/UPDATA_threeFullScreen", false);
    tileseList.forEach((item) => {
      item.tilese3d.show = false;
    });
    var box = viewer.entities.getById("modelOutLIne");
    viewer.entities.remove(box);
    DxCommonUtils.handleAdd3DTileset.deletes();
    if (this.TZId.length) {
      const n = this.TZId.length;
      for (let j = n - 1; j >= 0; j--) {
        const ent = viewer.entities.getById(this.TZId[j]);
        ent && viewer.entities.remove(ent);
        this.TZId.splice(j, 1)
      }
    }

    cesiumInit.destroy();
    // if (this.menuType === "drilling") {
    //   DxCommonUtils.handleBatchTurnHole.delDataSource();
    // } else if (this.menuType === "plane") {
    //   DxCommonUtils.handleDrawPlane.delDataSource();
    // } else if (this.menuType === "profile") {
    //   DxCommonUtils.handleDrawProfile.delDataSource();
    // } else {
    // }
    viewer.dataSources.removeAll();
    // DxCommonUtils.handleBatchTurnHole.delDataSource();
    // DxCommonUtils.handleDrawPlane.delDataSource();
    // DxCommonUtils.handleDrawProfile.delDataSource();
  },
  destroyed() {
    DxCommonUtils.removeAllEntities();
  },
};
</script>

<style lang="scss" scoped>
.loaing-box {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  z-index: 100000;
  border-right: 30px;
  // transform: translate(-50%, -50%);
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  background-color: rgba(24, 116, 205, 0.1);
  box-shadow: 0 0 6px #00b2ee, 0 0 2px #009acd inset;
  & > i {
    color: #299dc8;
    font-size: 60px;
    margin-bottom: 30px;
  }
  & > span {
    font-size: 16px;
    letter-spacing: 2px;
    color: #299dc8;
  }
}
.list-line-icon {
  width: 100px;
}
.promotion-all {
  width: 20px;
  height: 20px;
  text-align: center;
  line-height: 20px;
}
.demo-table-expand {
  font-size: 0;
}
.demo-table-expand label {
  width: 90px;
  color: #99a9bf;
}
.demo-table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
.pdf-body {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 4000;
  width: 100vw;
  height: 100vh;
  z-index: 4000;
  background-color: #817d7d;
  overflow: auto;
  padding: 15px;
  // span {
  //   display: block;
  //   width: 50%;
  // }
  // display: flex;
  // justify-content: center;
  // align-items: center;
  .pdf-body-cooper {
    position: fixed;
    top: 0;
    left: 0;
  }
  .pdf-color {
    position: fixed;
    top: 10px;
    right: 10px;
    font-size: 20px;
  }
}
</style>
<style>
.dx-body-container .el-checkbox {
  margin-right: 0px !important;
}
</style>
